// ActionScript file
import common.CommonFunction;
import common.Mask;

import customerapprovals.ViewCustomerDetails;

import mx.collections.ArrayCollection;
import mx.controls.Alert;
import mx.controls.DateField;
import mx.managers.PopUpManager;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;


[Embed(source="/images/success.png")]private var successIcon:Class;
[Embed(source="/images/error.png")]private var errorIcon:Class;
[Embed(source="/images/question.png")]private var questionIcon:Class;



public var infoObject:Object;

public function onCreationComplete():void{
	
	approveButton.enabled=false;
	
	infoObject = new Object();
	
	infoObject["date"] = new Date();
	
	getRegisteredCustomers.send(infoObject);
	Mask.show(CommonFunction.getConstants('pleaseWait'));	
	
}

public var customerXML:XML;
public var customerList:ArrayCollection;
public function onSuccess(event:ResultEvent):void{
	
	Mask.close();
	customerXML = event.result as XML;
	customerList = new ArrayCollection();
	
	for each(var obj:Object in customerXML.record){
		
		customerList.addItem({select:false,customerName:obj.customerName,phoneNumber:obj.phoneNumber,
								accountBal:obj.accountBal,gender:obj.gender,
								dob:obj.dob,address:obj.address,
								city:obj.city,state:obj.state,
								customerStatus:obj.customerStatus,country:obj.country,
								accountNumber:obj.accountNumber,customerImage:obj.customerImage,
								emailId:obj.emailId,customerId:obj.customerId});
		
	}	
		customerDetailsGrid.dataProvider = customerList;
}

public function onFailure(event:FaultEvent):void{
	Mask.close();
	
	Alert.show("Error in Connection..try again");
	
}

public var viewCustDetails:ViewCustomerDetails;
public var selectedRecord:ArrayCollection;
public function viewDetails():void{
	
	selectedRecord = new ArrayCollection();
	viewCustDetails = ViewCustomerDetails(PopUpManager.createPopUp(this,ViewCustomerDetails,true));			
	
	for each(var obj:Object in customerDetailsGrid.dataProvider){
		if(obj.select==true){
			
			selectedRecord.addItem({select:false,customerName:obj.customerName,phoneNumber:obj.phoneNumber,
								accountBal:obj.accountBal,gender:obj.gender,
								dob:obj.dob,address:obj.address,
								city:obj.city,state:obj.state,
								customerStatus:obj.customerStatus,country:obj.country,
								accountNumber:obj.accountNumber,customerImage:obj.customerImage,
								emailId:obj.emailId,customerId:obj.customerId});				
		}
		
	}
				viewCustDetails.nameField.text = selectedRecord.getItemAt(0).customerName;
				viewCustDetails.phoneField.text = selectedRecord.getItemAt(0).phoneNumber;
				viewCustDetails.balField.text = selectedRecord.getItemAt(0).accountBal;
				viewCustDetails.genderCombo.selectedItem = selectedRecord.getItemAt(0).gender;
				viewCustDetails.dateField.data = DateField.stringToDate(selectedRecord.getItemAt(0).dob,"YYYY/MM/DD");
				viewCustDetails.addressField.text = selectedRecord.getItemAt(0).address;
				viewCustDetails.city = selectedRecord.getItemAt(0).city;
				viewCustDetails.state = selectedRecord.getItemAt(0).state;
				viewCustDetails.statusCombo.selectedItem = selectedRecord.getItemAt(0).customerStatus;
				viewCustDetails.countryCombo.selectedItem = selectedRecord.getItemAt(0).country;
				viewCustDetails.accountField.text = selectedRecord.getItemAt(0).accountNumber;
				viewCustDetails.emailField.text = selectedRecord.getItemAt(0).emailId;
				viewCustDetails.customerImage = selectedRecord.getItemAt(0).customerImage;
				viewCustDetails.customerId = selectedRecord.getItemAt(0).customerId;
				viewCustDetails.initFunction = onCreationComplete;												
				PopUpManager.centerPopUp(viewCustDetails);
				viewCustDetails.setFocus();
	
	
}
